import {
	createStore
} from "vuex";
import user from './modules/user';
import persistedState from "vuex-persistedstate"

const store = createStore({
	state: { //存放状态
		username: '狐狸',
		openid: ''
	},
	mutations: {
		submitOpenId(state, val) {
			state.openid = val;
		}
	},
	actions: {
		openIdAction({
			commit
		}, val) {
			commit('submitOpenId', val);
		}
	},
	modules: {
		user
	},
	plugins: [
		persistedState({
			storage: {
				getItem: key => uni.getStorageSync(key),
				setItem: (key, value) => uni.setStorageSync(key, value),
				removeItem: key => uni.removeStorageSync(key)
			}
		})
	]
})

export default store;
